package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizOrderGoods;
import com.member.shop.domain.SysBizRafflePrize;
import com.member.shop.service.ISysBizRafflePrizeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 抽奖奖品Controller
 *
 * @author lxc
 * @date 2024-03-13
 */
@RestController
@RequestMapping("shop/raffle/prize")
public class SysBizRafflePrizeController extends BaseController {
    @Resource
    private ISysBizRafflePrizeService sysBizRafflePrizeService;

    private void setTenantId(SysBizRafflePrize sysBizRafflePrize) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizRafflePrize.setTenantId(tenantId);
        }
    }

    /**
     * 查询抽奖奖品列表
     */
    @PreAuthorize("@ss.hasPermi('raffle:prize:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizRafflePrize sysBizRafflePrize) {
        startPage();
        setTenantId(sysBizRafflePrize);
        List<SysBizRafflePrize> list = sysBizRafflePrizeService.selectSysBizRafflePrizeList(sysBizRafflePrize);
        return getDataTable(list);
    }

    /**
     * 导出抽奖奖品列表
     */
    @PreAuthorize("@ss.hasPermi('raffle:prize:export')")
    @Log(title = "抽奖奖品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizRafflePrize sysBizRafflePrize) {
        setTenantId(sysBizRafflePrize);
        List<SysBizRafflePrize> list = sysBizRafflePrizeService.selectSysBizRafflePrizeList(sysBizRafflePrize);
        ExcelUtil<SysBizRafflePrize> util = new ExcelUtil<SysBizRafflePrize>(SysBizRafflePrize.class);
        util.exportExcel(response, list, "抽奖奖品数据");
    }

    /**
     * 获取抽奖奖品详细信息
     */
    @PreAuthorize("@ss.hasPermi('raffle:prize:query')")
    @GetMapping(value = "/{prizeId}")
    public AjaxResult getInfo(@PathVariable("prizeId") Long prizeId) {
        return success(sysBizRafflePrizeService.selectSysBizRafflePrizeByPrizeId(prizeId));
    }

    /**
     * 获取活动列表
     */
    @PreAuthorize("@ss.hasPermi('raffle:prize:query')")
    @GetMapping(value = "/listActivity")
    public AjaxResult getActivityList(@PathVariable("prizeId") Long prizeId) {
        return success(sysBizRafflePrizeService.selectSysBizRafflePrizeByPrizeId(prizeId));
    }

    /**
     * 新增抽奖奖品
     */
    @PreAuthorize("@ss.hasPermi('raffle:prize:add')")
    @Log(title = "抽奖奖品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizRafflePrize sysBizRafflePrize) {
        return toAjax(sysBizRafflePrizeService.insertSysBizRafflePrize(sysBizRafflePrize));
    }

    /**
     * 修改抽奖奖品
     */
    @PreAuthorize("@ss.hasPermi('raffle:prize:edit')")
    @Log(title = "抽奖奖品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizRafflePrize sysBizRafflePrize) {
        return toAjax(sysBizRafflePrizeService.updateSysBizRafflePrize(sysBizRafflePrize));
    }

    /**
     * 删除抽奖奖品
     */
    @PreAuthorize("@ss.hasPermi('raffle:prize:remove')")
    @Log(title = "抽奖奖品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{prizeIds}")
    public AjaxResult remove(@PathVariable Long prizeIds) {
        return toAjax(sysBizRafflePrizeService.deleteSysBizRafflePrizeByPrizeId(prizeIds));
    }
}
